package com.heima.thread;

public class InterruptDemo02 {
    public static void main(String[] args) throws InterruptedException {
        // // 1. 打断阻塞的线程
        // Thread t1 = new Thread(() -> {
        //     System.out.println("t1正在运行...");
        //     try {
        //         Thread.sleep(5000);
        //     } catch (InterruptedException e) {
        //         throw new RuntimeException(e);
        //     }
        // }, "t1");
        // t1.start();
        // Thread.sleep(500);
        // t1.interrupt();
        // System.out.println(t1.isInterrupted());

        // 2. 打断阻塞的线程
        Thread t2 = new Thread(() -> {
            while(true)
            {
                Thread current = Thread.currentThread();
                boolean interrupted = current.isInterrupted();
                if(interrupted){
                    System.out.println("打断状态: "+interrupted);
                    break;
                }
            }
        }, "t2");
        t2.start();
        Thread.sleep(500);
        t2.interrupt();
        System.out.println(t2.isInterrupted());
    }
}
